<?php
/**
 * exportAirportInfo.php
 * 描述
 *
 * 作者:  胡毅 (huyi@comsenz.com)
 * 创建时间: 2012-10-13 下午12:09:33
 * 修改记录:
 *
 * $id$
 */
set_time_limit(0);
define('ROOT_PATH', dirname(dirname(dirname(dirname(dirname(dirname(dirname(__FILE__))))))));
define('APP_PATH', dirname(dirname(dirname(dirname(dirname(__FILE__))))));
error_reporting(E_ALL ^ E_NOTICE);

require_once (ROOT_PATH . '/framework/library/Bootstrap.php');

try {

    $options = array('interface' => 'runtime');
    $bootstrap = & Bootstrap::factory($options);
    $bootstrap->run();
} catch (Exception $e) {

    echo $e->getMessage();
    exit();
}

class exportAirportInfo{

    private $_file;

    public function __construct() {

        $this->_file = file('threeCode.txt');
        if(!$this->_file) {
            echo '找不到文件' . PHP_EOL;
            exit;
        }
    }

    public function run() {

        $airportCode =& Service::factory('Flight_Service_AirportCode');
        if(is_array($this->_file)) {
            foreach ($this->_file as $line) {
                $data = explode("\t", $line);
                if(count($data)<2){
                    continue;
                }
                $addData = array('threeCode' => trim($data[1]),
                                 'acCityName' => trim($data[0]));
                if($airportCode->get(trim($data[1]))) {
                    $airportCode->update(trim($data[1]), $addData);
                } else {
                    $airportCode->add($addData);
                }
                echo $data[1] . '    success' . PHP_EOL;
            }
        }
    }
}


try {
    $obj = new exportAirportInfo();
    $obj->run();
} catch (Exception $e) {
    echo $e->getMessage();
}